<?php
namespace app\mini\controller;

use think\Controller;
use think\Config;
use think\Request;
use app\mini\model\Project;

class Common extends Controller
{

    /**
     * 基础控制器初始化
     * @author hey_heyang(635870453@qq.com)
     */
    public function _initialize()
    {
        $this->ProjectInt();
    }


    //项目初始化
    private function ProjectInt(){
        $ProModel = new Project();
        $nowTime = time();
        //预热项目
        $ProModel->where(['start_time'=>['lt',$nowTime],'status'=>['eq',1]])->update(['status'=>2]);
        //认投中项目
        $ProList = $ProModel->where(['status'=>2])->select();
        if($ProList){
            foreach($ProList as $Pro){
                $money = GetProjectBar($Pro['id']);
                if($Pro['end_time'] <= $nowTime && $money < $Pro['target_code']){
                    $cha=$Pro['target_code']-$money;
                    $data['status'] = -1;
                    //$data['basic_code']=$cha;
                    //$ProModel->where(['id'=>$Pro['id']])->setInc('basic_code',$cha);
                    $ProModel->where(['id'=>$Pro['id']])->update($data);
                }
                if($money >= $Pro['target_code'] ){
                    $data['status'] = 3;
                    $ProModel->where(['id'=>$Pro['id']])->update($data);
                }
            }
        }
    }

}